package com.car.account.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.car.account.controller.form.storesDimissionForm.OverruleDimissionForm;
import com.car.account.controller.form.storesDimissionForm.SelectDimissionForm;
import com.car.account.dto.storesDimissionDto.SelectDimissionByStateDto;
import com.car.account.param.storesDimissionParam.OverruleDimissionParam;
import com.car.account.param.storesDimissionParam.SelectDimissionParam;
import com.car.account.service.StoresDimissionService;
import com.car.commons.core.model.Result;
import com.car.commons.core.util.JwtUtil;
import com.car.commons.web.util.WebUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 董旭
 * @since 2024-08-28
 */
@RestController
@RequestMapping("/storesDimission")
@Api(tags = "离职申请信息")
public class StoresDimissionController {

    @Resource
    private StoresDimissionService storesDimissionService;

    @GetMapping("/clerkDimissionApplication.md")
    @ApiOperation(value = "店员离职申请")
    public Result clerkDimissionApplication(String dimissionInfo) throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer clerkId = JwtUtil.getClerkId(token);
        storesDimissionService.clerkDimissionApplication(clerkId, dimissionInfo);
        return Result.getResult().setMsg("店员离职申请成功");
    }

    @PostMapping("/selectDimissionByState.md")
    @ApiOperation(value = "店长根据申请状态查看离职申请")
    public Result<Page> selectDimissionByState(@RequestBody SelectDimissionForm form) throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer clerkId = JwtUtil.getClerkId(token);
        SelectDimissionParam param = BeanUtil.toBean(form, SelectDimissionParam.class);
        param.setClerkId(clerkId);
        Page<SelectDimissionByStateDto> page = storesDimissionService.selectDimissionByState(param);
        return Result.getResult(Page.class)
                .setData(page)
                .setMsg("店长根据申请状态查看离职申请成功");
    }

    @GetMapping("/passDimissionById.md")
    @ApiOperation(value = "店长通过id通过离职申请")
    public Result passDimissionById(Integer dimissionId) throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer clerkId = JwtUtil.getClerkId(token);
        storesDimissionService.passDimissionById(clerkId, dimissionId);
        return Result.getResult().setMsg("店长通过id通过离职申请");
    }

    @PostMapping("/overruleDimissionById.md")
    @ApiOperation(value = "店长通过id驳回离职申请")
    public Result overruleDimissionById(@RequestBody OverruleDimissionForm form) throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer clerkId = JwtUtil.getClerkId(token);
        OverruleDimissionParam param = BeanUtil.toBean(form, OverruleDimissionParam.class);
        param.setClerkId(clerkId);
        storesDimissionService.overruleDimissionById(param);
        return Result.getResult().setMsg("店长通过id驳回离职申请");
    }

}

